﻿Imports Microsoft.VisualBasic
Imports System.ComponentModel
Imports System.Data
<System.ComponentModel.DataObject()> _
Public Class Municipio
    Inherits BDDatos
    Sub New()
        Me.Tabla = "municipios"
        Me.Vista = "municipios"
        Me.VistaDB = "municipios"
    End Sub
    <DataObjectMethodAttribute(DataObjectMethodType.Select, True)> _
    Public Function Insert(ByVal codD As Integer, ByVal codM As Integer, ByVal nomM As String) As String
        Me.Conectar()
        Me.ComenzarTransaccion()
        Try
            Me.querystring = "Insert into Municipos (Cod_Depart,Cod_Muni,Nom_Muni) Values(:cod_dep,:cod_muni,:nom_mun)"
            Me.CrearComando(querystring)


            Me.AsignarParametroEntero(":cod_dep", codD)
            Me.AsignarParametroEntero(":cod_muni", codM)
            Me.AsignarParametroCadena(":nom_mun", nomM)

            Me.num_reg = EjecutarComando()
            Me.Msg = "Operacion Realizada Exitosamente - " + num_reg.ToString + " Filas Afectadas"
            Me.lErrorG = False

            Me.ConfirmarTransaccion()
        Catch ex As Exception
            CancelarTransaccion()
            Me.lErrorG = True
            Me.Msg = "Err: " + ex.Message
        Finally
            Me.Desconectar()
        End Try
        Return Msg
    End Function
    <DataObjectMethodAttribute(DataObjectMethodType.Select, True)> _
    Public Function GetByDpto(ByVal Cod_dpto As String) As DataTable
        Me.Conectar()
        Me.querystring = "Select * from MUNICIPIOS where cod_dpto=:Cod_Dpto"
        CrearComando(querystring)
        Me.AsignarParametroCadena(":Cod_Dpto", Cod_dpto)
        'Throw New Exception(vComando.CommandText)
        Dim dt As DataTable = EjecutarConsultaDataTable()
        Me.Desconectar()
        Return dt
    End Function

    Public Function Update(ByVal PK As String, ByVal codD As Integer, ByVal codM As Integer, ByVal nomM As String) As String
        Me.Conectar()
        Me.ComenzarTransaccion()
        Try
            Me.querystring = "Update MUNICIPIOS set Cod_depart=:cod_depart, Cod_Muni:cod_muni Nom_Muni=:nom_muni  Where Cod_depart and Cod_Muni=:PK"
            Me.CrearComando(querystring)
            Me.AsignarParametroEntero(":cod_depart", codD)
            Me.AsignarParametroEntero(":cod_muni", codM)
            Me.AsignarParametroCadena(":nom_muni", nomM)
            Me.AsignarParametroCadena(":PK", PK)
            Me.num_reg = EjecutarComando()
            Me.Msg = "Se realizo la Operacion Exitosamente - " + num_reg.ToString + " Filas Afectadas"
            Me.lErrorG = False
            Me.ConfirmarTransaccion()
        Catch ex As Exception
            CancelarTransaccion()
            Me.lErrorG = True
            Me.Msg = "Err: " + ex.Message
        Finally
            Me.Desconectar()
        End Try
        Return Msg
    End Function

    'Public Function Delete(ByVal codE As String) As String
    '    Me.Conectar()
    '    ComenzarTransaccion()
    '    Try
    '        Me.querystring = "Delete from MUNICIPIOS where Cod_depart=:Cod_depart and Cod_Muni:cod_muni"
    '        CrearComando(querystring)
    '        Me.AsignarParametroCadena(":Cod_depart", codE)
    '        EjecutarComando()
    '        Msg = MsgOk
    '        ConfirmarTransaccion()
    '    Catch ex As Exception
    '        CancelarTransaccion()
    '        Msg = ex.Message
    '    Finally
    '        Me.Desconectar()
    '    End Try
    '    Return Msg
    'End Function

    '    Public Overloads Function GetRecords(ByVal busc As String) As DataTable
    '        Me.Conectar()
    '        If busc = "" Then
    '            querystring = "SELECT * FROM vmunicipios"
    '            Me.CrearComando(querystring)
    '        Else
    '            querystring = "SELECT * FROM vmunicipios where Cod_Muni Like :Buscar or Nom_Muni Like :Buscar"
    '            Me.CrearComando(querystring)
    '            AsignarParametroCadena(":Buscar", "%" & busc & "%")
    '            AsignarParametroCadena(":Buscar", "%" & busc & "%")
    '        End If
    '        Dim dataTb As DataTable = Me.EjecutarConsultaDataTable()
    '        Me.Desconectar()
    '        Return dataTb

    ' End Function


End Class
